package com.pearl.jacksoncore.demo.databind.custom;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.deser.BeanDeserializerModifier;
import com.fasterxml.jackson.databind.deser.DeserializerFactory;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fasterxml.jackson.databind.ser.SerializerFactory;
import com.fasterxml.jackson.databind.ser.impl.IndexedStringListSerializer;
import com.fasterxml.jackson.databind.ser.std.DateSerializer;
import com.pearl.jacksoncore.demo.databind.ser.ModifyPasswordBeanSerializerModifier;

import java.util.ArrayList;
import java.util.List;

/**
 * 也可以在``
 * @author TD
 * @version 1.0
 * @date 2024/4/11
 */
public class CustomTest {

    public static void main(String[] args) throws JsonProcessingException {

        ObjectMapper objectMapper = new ObjectMapper();

        UserVO userVO = new UserVO();
        userVO.setId(1699657986705854464L);
        userVO.setUsername("jack");
        List<String> roleList = new ArrayList<>();
        roleList.add("管理员");
        roleList.add("经理");
        userVO.setRoleList(roleList);

/*        SimpleModule customModule = new SimpleModule(); // 自定义模块
        // 注册自定义的序列化器/反序列化器
        customModule.addSerializer(List.class,ListToStringJsonSerializer.instance);
        customModule.addDeserializer(List.class, ListToStringJsonDeserializer.instance);
        objectMapper.registerModule(customModule); // 注册自定义模块*/

        // 序列化
        String userVoJson = objectMapper.writeValueAsString(userVO);
        System.out.println(userVoJson);



/*
        OrgInfo orgInfo=new OrgInfo();
        orgInfo.setName("大华科技");
        orgInfo.setCode(123456);
        List<String> children=new ArrayList<>();
        children.add("长沙大华分公司");
        orgInfo.setChildren(children);
        UserInfo userInfo=new UserInfo();
        userInfo.setName("张三");
        orgInfo.setOrgAdmin(userInfo);
*/


    }
}
